package ${packages.controller};

import ${packages.dto}.${classInfo.className}CreateRequest;
import ${packages.dto}.${classInfo.className}Response;
import ${packages.dto}.${classInfo.className}UpdateRequest;
import ${packages.dto}.${classInfo.className}QueryRequest;
import ${packages.service}.${classInfo.className}Service;
import ${basePackage}.common.BaseResponse;
import ${basePackage}.common.ResultUtils;
import ${basePackage}.common.PageResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * ${moduleDisplayName} 控制器
 * ${moduleSummary}
 */
@RestController
@RequestMapping("/${apiBasePath}")
@RequiredArgsConstructor
@Validated
@Tag(name = "${moduleDisplayName}管理", description = "${moduleSummary}")
public class ${classInfo.className}Controller {

    private final ${classInfo.className}Service ${classInfo.className?uncap_first}Service;

    @PostMapping
    @Operation(summary = "${operationVerbs.post} ${moduleDisplayName}")
    public BaseResponse<${classInfo.className}Response> create(@RequestBody @Valid ${classInfo.className}CreateRequest request) {
        return ResultUtils.success(${classInfo.className?uncap_first}Service.create(request));
    }

    @PutMapping("/{id}")
    @Operation(summary = "${ScaffoldNameUtils.resolveOperationVerb("PUT")} ${moduleDisplayName}")
    public BaseResponse<${classInfo.className}Response> update(@PathVariable ${primaryKeyFieldType} ${primaryKeyFieldName},
                                                              @RequestBody @Valid ${classInfo.className}UpdateRequest request) {
        return ResultUtils.success(${classInfo.className?uncap_first}Service.update(${primaryKeyFieldName}, request));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "${operationVerbs.delete} ${moduleDisplayName}")
    public BaseResponse<Boolean> delete(@PathVariable ${primaryKeyFieldType} ${primaryKeyFieldName}) {
        ${classInfo.className?uncap_first}Service.delete(${primaryKeyFieldName});
        return ResultUtils.success(Boolean.TRUE);
    }

    @GetMapping("/{id}")
    @Operation(summary = "${operationVerbs.get} ${moduleDisplayName}详情")
    public BaseResponse<${classInfo.className}Response> detail(@PathVariable ${primaryKeyFieldType} ${primaryKeyFieldName}) {
        return ResultUtils.success(${classInfo.className?uncap_first}Service.findById(${primaryKeyFieldName}));
    }

    @GetMapping
    @Operation(summary = "${operationVerbs.get} ${moduleDisplayName}列表")
    public BaseResponse<PageResponse<${classInfo.className}Response>> list(@Valid ${classInfo.className}QueryRequest request) {
        return ResultUtils.success(${classInfo.className?uncap_first}Service.page(request));
    }
}
